// pages/calendar/editPersonalDetail/editPersonalDetail.js
import {getScheduleInfo,personalInformation} from '../../../api/calendar'
import {getToken} from '../../../utils/storage'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    careerindex:0,
    careerarray:['策划','主持','摄影','摄像','跟妆','花艺','灯光','督导','演艺','场布','DJ','其他'],
    //城市
    region: [],
    // regionjudge:null,
    genderindex:0,
    genderarray:['男','女'],
    showregion:false,
    showcareer:false,
    showgender:false,
    // customItem: '全部'
    //用户信息
    userInformation:'',
    avator:'',
    userName:'',
    //简介
    remark1:'',
    //性别
    gender:'',
    //视频
    worksvideo:""
  },
  //名字输入
  usernameinp(e) {
    this.setData({
      userName: e.detail.value
    })
  },
  //简介输入
  inputvalue(e) {
     
    this.setData({
      remark1: e.detail.value
    })
  },
  //保存资料
  clickSave() {
    personalInformation({
      "avator":this.data.avator,
      "emcee_name":this.data.userName,
      "common_address":this.data.region,
      "sex":this.data.gender,
      "user_describe":this.data.remark1,
      "works":this.data.worksvideo
    }).then((res)=>{
       
      wx.showToast({
        title: '修改成功',
      })
      
      setTimeout(()=>{
        wx.navigateBack({
          delta: 1,
        })
      },1000)
    })
    // ;
  },
  //选择头像
  chooseAvator (){
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType:['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        ;
        const tempFilePaths = res.tempFilePaths
        const tmpToken = getToken();
        wx.uploadFile({
          filePath: tempFilePaths[0],
          name: 'file',
          header:{
            'token': tmpToken,
            'Content-Type': 'application/x-www-form-urlencoded'
          },
          url: 'https://www.hudongmiao.com/beiJing/shangchuanTomcat',
          success(res) {
            let webidpic = JSON.parse(res.data)
            ;
            that.setData({
              avator:webidpic.data.filePath
            })
          }
        })
      }
    })
  },
  //选择性别
  bindgenderChange(e) {
    this.setData({
      showgender:true,
      genderindex:e.detail.value,
      gender:Number(e.detail.value) + 1
    })
    ;
  },
  //选择职业
  bindPickerChange(e) {
    this.setData({
      showcareer:true,
      careerindex: e.detail.value
    })
  },
  //地区选择
  bindRegionChange(e){
     
    this.setData({
      region:e.detail.value,
      showregion:true,
      regionjudge:true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    getScheduleInfo({
      'id':''
    }).then((res)=>{
       
      ;
      // let regionarray = [];
      // regionarray[0] = 
      // res.data.user.common_address == undefined
      if(res.data.user.common_address == undefined) {
        this.setData({
          userInformation:res.data.user,
          avator:res.data.user.avator,
          userName:res.data.user.emcee_name,
          remark1:res.data.user.user_describe,
          region:"",
          // regionjudge:false,
          // genderindex:Number(res.data.user.sex) - 1,
          showgender: true,
          worksvideo:res.data.user.works
        })
      }else {
        this.setData({
          userInformation:res.data.user,
          avator:res.data.user.avator,
          userName:res.data.user.emcee_name,
          remark1:res.data.user.user_describe,
          region:res.data.user.common_address.split(","),
          // region:"",
          // genderindex:Number(res.data.user.sex) - 1,
          showgender: true,
          worksvideo:res.data.user.works
        })
      }
      // res.data.user.sex == ""
      if(res.data.user.sex == "undefined") {
        this.setData({
          showgender:false
        })
      }else {
        this.setData({
          genderindex:Number(res.data.user.sex) - 1,
          // showgender:false
        })
      }
      ;
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})